import { EditPen, Share } from '@element-plus/icons-vue'
import { BankInfo, BankHeaderConfig, DefaultBankInfo, QuestionParams } from './data.d'

//以下皆为推测的后端接口，尚未实现

/**
 * 将API返回的BankInfo转换为TopicHeader组件所需的配置
 */
export const bankInfoToHeaderConfig = (bankInfo: BankInfo): BankHeaderConfig => ({
  icon: bankInfo.icon || '/default-bank-icon.png',
  iconAlt: `${bankInfo.name}图标`,
  title: bankInfo.name,
  description: bankInfo.description,
  buttons: [
    { text: '开始刷题', type: 'primary', action: 'start' },
    { text: '在线测验', icon: EditPen, action: 'test' },
    { text: '分享', icon: Share, action: 'share' },
  ],
})

/**
 *  当API请求失败时使用
 */
export const getDefaultBankInfo = (): DefaultBankInfo => ({
  icon: null,
  title: 'Java 热门面试题 200 道',
  description:
    '2024 最新 Java 热门面试题 200 道，涵盖 Java、MySQL、Redis、Spring、SpringBoot、SpringCloud、计算机网络、操作系统、消息队列、Netty、后端场景题、线上问题排查、后端系统设计题等',
  categoryId: 101, // 默认分类ID
})

/**
 * 基于题库标题
 */
export const setPageTitle = (bankTitle: string): void => {
  document.title = `${bankTitle} - 面试题库`
}

/**
 * 根据按钮动作执行相应逻辑
 */
export const handleHeaderButtonClick = (action: string): void => {
  switch (action) {
    case 'start':
      console.log('开始刷题')
      // TODO: 实现开始刷题逻辑
      break
    case 'test':
      console.log('在线测验')
      // TODO: 实现在线测验逻辑
      break
    case 'share':
      console.log('分享题库')
      // TODO: 实现分享题库逻辑
      break
    default:
      console.warn(`未知的按钮动作: ${action}`)
  }
}
